
import Vue from 'vue'
import message from './Message.vue'
// 1.用 Vue.extend 创建组件的模板（构造函数）
const messageConstructor = Vue.extend(message)
let instance
let index = 0
const Message = function (options, duration) { // options是传入的参数配置 {message: '成功',type: "success"offset: 80}
  // 2.实例化组件
  // eslint-disable-next-line new-cap
  instance = new messageConstructor({ data: options }) // 把options导入data中
  // 3.组件挂载
  setTimeout(() => {
    index--
    instance.verticalOffset = 0
  }, duration || 3000)
  index++
  instance.verticalOffset = index
  instance.$mount()
  document.body.appendChild(instance.$el)
  // 设置offset
  instance.show = options.show || false
  instance.duration = duration || 3000
  return instance
}
export default Message
